@extends('admin.common.main')

@section('css')
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
@endsection
@section('cnt')
    <div class="layui-form layuimini-form" id="create" lay-filter="example">
        @csrf
        <div class="layui-form-item">
               <label class="layui-form-label required">是否顶级</label>
               <div class="layui-input-block">
                   <select name="pid" id="pid" lay-verify="required" lay-filter="aihao">
                       <option value="0" >=顶级菜单=</option>
                       @foreach($data as $item)
                           <option value="{{$item->id}}">{{$item->name}}</option>
                       @endforeach
                   </select>
               </div>
           </div>
           <div class="layui-form-item">
               <label class="layui-form-label required">权限名称</label>
               <div class="layui-input-block">
                   {{--                lazy 延时绑定 --}}
                   <input type="text" name="name" id="name" lay-verify="required"  class="layui-input">
               </div>
           </div>
           <div class="layui-form-item">
               <label class="layui-form-label">路由别名</label>
               <div class="layui-input-block">
                   <input type="text" name="route_name" id="route_name"  class="layui-input">
               </div>
           </div>
           <div class="layui-form-item">
               <label class="layui-form-label">是否为菜单</label>
               <div class="layui-input-block">
                   <input type="radio" name="is_menu"  value="0" title="否" checked="">
                   <input type="radio" name="is_menu" value="1" title="是"  >
               </div>
           </div>
           <div class="layui-form-item">
               <div class="layui-input-block">
                   <button class="layui-btn layui-btn-normal" lay-submit   lay-filter="saveBtn">确认保存</button>
               </div>
           </div>
    </div>
@endsection

@section('js')
{{--    <script src="{{ asset('js/vue.js') }}" charset="utf-8"></script>--}}
    <script>
        {{--$ = layui.$;--}}
        {{--new Vue({--}}
        {{--    el: '#create',--}}
        {{--    data:{--}}
        {{--       info:{--}}
        {{--           _token:'{{csrf_token()}}',--}}
        {{--           name:"",--}}
        {{--           route_name:"",--}}
        {{--           pid:0,--}}
        {{--           is_menu:0,--}}
        {{--       }--}}
        {{--    },--}}
        {{--    methods:{--}}
        {{--        //es7 异步变同步--}}
        {{--       async onSubmit(){--}}
        {{--            console.error(this.info);--}}
        {{--            let url = '{{route('admin.node.store')}}';--}}
        {{--            let ret = await $.post(url,this.info);--}}
        {{--            console.error(ret);--}}
        {{--       }--}}
        {{--    },--}}
        {{--    mounted:function () {--}}
        {{--        this.$nextTick(function () {--}}
        {{--            layui.use(['form'], function(){--}}
        {{--                layui.form.render()--}}
        {{--            });--}}
        {{--        });--}}
        {{--    },--}}
        {{--    updated: function () {--}}
        {{--        this.$nextTick(function () {--}}
        {{--            layui.use(['form'], function(){--}}
        {{--                layui.form.render()--}}
        {{--            });--}}
        {{--        });--}}
        {{--    }--}}
        {{--});--}}

        layui.use(['form','upload','http'], function () {
            var form = layui.form,
                layer = layui.layer,
                http  = layui.http,
                $ = layui.$;
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                console.error(data);
                http.httpajax('{{route('admin.node.store')}}', data.field,"POST",function(res) {
                    if(res.code === 200){
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            // 关闭弹出层
                            layer.close();
                            window.parent.location.reload();//刷新父页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            });
        });
    </script>
@endsection

